1. Technical Field
This invention generally relates to computer systems, and more specifically relates to apparatus and methods for processing database queries.
2. Background Art
Database systems have been developed that allow a computer to store a large amount of information in a way that allows a user to search for and retrieve specific information in the database. For example, an insurance company may have a database that includes all of its policy holders and their current account information, including payment history, premium amount, policy number, policy type, exclusions to coverage, etc. A database system allows the insurance company to retrieve the account information for a single policy holder among the thousands and perhaps millions of policy holders in its database.
Retrieval of information from a database is typically done using queries. A query usually specifies conditions that apply to one or more columns of the database, and may specify relatively complex logical operations on multiple columns. The database is searched for records that satisfy the query, and those records are returned as the query result. Structured Query Language (SQL) is one specific query language that may be used to query a database.
An SQL query typically includes a “SELECT” statement or clause that specifies what data is desired. SQL also includes a construct known as a “HAVING” clause that may specify additional restrictions on the data. When an SQL query has a HAVING clause, the SELECT clause is processed first to generate intermediate results, typically in the form of a temporary table. The HAVING clause is then applied to the intermediate results to generate the result set for the query. Sometimes the HAVING clause significantly reduces the amount of data in the intermediate results. In these cases, the database engine goes to significant work to assemble data into the intermediate results, only to discard much of the data once the HAVING clause is processed. Without a way to take the HAVING clause into account while generating the intermediate results, the database industry will continue to suffer from inefficient methods for processing queries with a HAVING clause.